rm(list = ls())

## 

library(tidyverse)

## Get data

df <- read_rds("data/Data_Clean.rds") %>% 
  mutate(year = as.numeric(year)) %>% 
  mutate(treat_categ = recode(treat_categ,
                              'none' = 'Unaffected',
                              'schwach' = 'Weakly affected',
                              'schwer' = 'Highly affected',
                              'sehr schwer' = 'Highly affected')) %>%
  mutate(treat_categ = fct_relevel(treat_categ, 
                                   'Unaffected', 'Weakly affected'))

## Get Green party support trends 

trends <- df %>% 
  group_by(year, treat_categ) %>% 
  summarise(greens = mean(greens, na.rm = T) * 100) %>% 
  filter(!is.na(treat_categ)) %>% 
  mutate(treat_categ = fct_rev(treat_categ))

p1 <- ggplot(trends, 
             aes(year, greens, treat_categ)) +
  geom_vline(xintercept = 2020.5, linetype = 'dotted') +
  geom_line(aes(color = treat_categ)) +
  geom_point(aes(color = treat_categ)) +
  theme_bw() +
  scale_x_continuous(breaks = unique(df$year)) +
  scale_color_grey(name = 'Flood intensity', ) +
  scale_size_manual(values = c(0.6, 0.9, 1.2)[3:1],
                    name = 'Flood intensity') +
  xlab('Election') +
  ylab('Green party\nvote share (%)') +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, 
                                   hjust = 1)) +
  theme(legend.position = 'bottom') +
  guides(color=guide_legend(ncol=2))
p1
